package com.bezdelnick.forum.web.resource;

import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.IResource;
import org.apache.wicket.request.resource.ResourceStreamResource;
import org.apache.wicket.util.file.File;
import org.apache.wicket.util.resource.FileResourceStream;

import java.util.jar.Attributes;

/**
 * Created by IntelliJ IDEA.
 * User: Bezdelnick
 * Date: 04.09.12
 * Time: 9:41
 * To change this template use File | Settings | File Templates.
 */
public class FolderContentResource implements IResource {
    private final File rootFolder;

    public FolderContentResource(File rootFolder) {
        this.rootFolder = rootFolder;
    }

    public void respond(Attributes attributes) {
        PageParameters parameters = attributes.getParameters();
        String fileName = parameters.get(0).toString();
        File file = new File(rootFolder, fileName);
        FileResourceStream fileResourceStream = new FileResourceStream(file);
        ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
        resource.respond(attributes);
    }
}